<?php

class ASolicitudRepuestosAutomatica {

    public function __construct(){
	}
	public function descuentoAlmacen(EFacade & $facade)
	{

		$docSRA = & $facade->getDocumentRoot();
		$usuario=NULL;
		$ezpdo_= getManager();
		$docSRA->epSetDirty(TRUE);
		$workflows = & $facade->getWorkflow();
		$workflows->epSetDirty(TRUE);
		$transSetOSL = & EFacade :: getCurrentTransSetAuto($workflows, /* MTrans :: $TYPE_AUTO_AGENT */ 2);
		$listaWT= &$workflows->getWorkTransList();
		$transOSL = $transSetOSL->getTransByName('t3');
		$facade->fireTrans($transOSL,$usuario,'Creacion de Ordenes', TRUE);	

		/********** LIBERAR LA RESERVA *************/
		$consulta = "from MReservaRepuesto as t where t.solicitud = ?";
		$reservaciones = $ezpdo_->find($consulta,$docSRA);
		foreach($reservaciones as $reservacion){
			//echo "<hr>reserva: ",$reservacion;
			$ezpdo_->delete($reservacion);
		}
		/*******************************************/
		
		//Disparar la OM
		$OM = $docSRA->ordenMantenimiento;
		$workflow = & $OM->getWorkflowRef();
		$facade->session->refresh($workflow);
		$newEfacade = & EFacade :: initWorkflowWithoutRole($facade->session, $OM, 3);//tipo Process
		$transSet = & EFacade :: getCurrentTransSetAuto($workflow, /*PROCESS */ 3);
		$trans = $transSet->getTransByName('t12');
		$role = null;
		//Solo si esta disponible la t15
		if($trans){
			$newEfacade->fireTrans($trans, $role, "Culmina",TRUE);
			$workflow->epSetDirty(TRUE);
			$OM->epSetDirty(TRUE);
			$newEfacade->saveWorkflow();
		}		
	}
	public function culminarSolicitud(EFacade & $facade)
	{
		$docSRA = & $facade->getDocumentRoot();
	
		//Disparar la OM
		$OM = $docSRA->ordenMantenimiento;
		$workflow = & $OM->getWorkflowRef();
		$facade->session->refresh($workflow);
		$newEfacade = & EFacade :: initWorkflowWithoutRole($facade->session, $OM, 3);//tipo Process
		$transSet = & EFacade :: getCurrentTransSetAuto($workflow, /*PROCESS */ 3);
		$trans = $transSet->getTransByName('t15');
		$role = null;
		//Solo si esta disponible la t15
		if($trans){
			$newEfacade->fireTrans($trans, $role, "Culmina",TRUE);
			$workflow->epSetDirty(TRUE);
			$OM->epSetDirty(TRUE);
			$newEfacade->saveWorkflow();
		}	
	
		$usuario=NULL;
		$ezpdo_= getManager();
		$docSRA->epSetDirty(TRUE);
		$workflows = & $facade->getWorkflow();
		$workflows->epSetDirty(TRUE);
		$transSetOSL = & EFacade :: getCurrentTransSetAuto($workflows, /* MTrans :: $TYPE_AUTO_AGENT */ 2);
		$listaWT= &$workflows->getWorkTransList();
		$transOSL = $transSetOSL->getTransByName('t5');
		$facade->fireTrans($transOSL,$usuario,'Creacion de Ordenes', TRUE);	
		
		
	}
}
?>